
package com.ami.kvm.jviewer.gui;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.jvvideo.JVVideo;
import com.ami.kvm.jviewer.kvmpkts.KVMClient;
import com.ami.kvm.jviewer.videorecord.DisplayVideoDataTask;
import com.ami.kvm.jviewer.videorecord.VideoRecordApp;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.TimerTask;
import javax.imageio.ImageIO;

class VideoRecordStart extends TimerTask {
	JViewerApp RCApp = JViewerApp.getInstance();
	private int init_fps = 0;
	private Date CurrTime = new Date(0L);
	private Date RunTime = new Date(0L);
	private int num_blank_frames = 0;

	private static final int VIDEO_FPS = 3;

	public void run()
   {
     int i = 333;
     
 
     this.CurrTime = new Date(System.currentTimeMillis() / 1000L);
     this.RunTime = this.RCApp.getM_videorecord().TimeToRun;
     
     if (!JViewer.isdownloadapp()) {
       this.RCApp.getM_wndFrame().getWindowMenu().setMessage(LocaleStrings.getString("U_3_VR") + "(" + (this.RunTime.getTime() - this.CurrTime.getTime()) + " Sec)");
     }
     if ((this.CurrTime.before(this.RunTime)) && (!JViewer.isdownloadapp())) {
       captureFrames();
       
       try
       {
         synchronized (this.RCApp.getM_videorecord().obj) {
           this.RCApp.getM_videorecord().obj.wait(i);
         }
       } catch (Exception e) {
         Debug.out.println(e);
 
       }
       
 
     }
     else if (((DisplayVideoDataTask.run) || (this.CurrTime.getTime() <= this.RunTime.getTime())) && (JViewer.isdownloadapp()))
     {
       try
       {
         synchronized (this.RCApp.getM_videorecord().obj) {
           this.RCApp.getM_videorecord().obj.wait(i);
         }
       } catch (Exception localException) {
         Debug.out.println(localException);
       }
       
 
       if (VideoRecord.Recording_Started) {
         captureFrames();
       }
     } else {
       cancel();
       this.RCApp.getM_videorecord().OnVideoRecordStop();
     }
   }

	public void makeVideo(String paramString) throws MalformedURLException {
		this.CurrTime = new Date(System.currentTimeMillis() / 1000L);

		long l2 = this.RunTime.getTime() - this.CurrTime.getTime();
		if (l2 < 0L)
			l2 = 0L;
		long l1;
		if ((!JViewer.isdownloadapp()) && (!JViewer.isplayerapp())) {
			l1 = VideoRecord.RecordStopTimer - l2;
		} else {
			l1 = JViewerApp.getInstance().getVideorecordapp().getDuration();
		}
		String str = JViewerApp.getInstance().getM_videorecord().Temp_store_Path;
		ImagesToVideo localImagesToVideo = new ImagesToVideo(paramString, str, VideoRecord.TotalFrames, l1);
	}

	public File getFile(int paramInt, String paramString) {
		String str = "file" + paramInt + ".jpeg";
		File localFile = new File(paramString, str);
		return localFile;
	}

	private void captureFrames() {
		if (JViewerApp.getInstance().getKVMClient().m_isBlank == true) {

			this.num_blank_frames += 1;
			Debug.out.println("num_blank_frames " + this.num_blank_frames);
			if (!JViewerApp.getInstance().getM_videorecord().singleVideo) {
				return;
			}
		}

		File localFile = getFile(VideoRecord.TotalFrames, this.RCApp.getM_videorecord().Temp_store_Path);
		VideoRecord.TotalFrames += 1;
		try {
			localFile.createNewFile();
			ImageIO.write(this.RCApp.getRCView().getImage(), "jpeg", localFile);
		} catch (IOException localIOException) {
			Debug.out.println(localIOException);
			String str = LocaleStrings.getString("V_12_VRS");
			cancel();
			this.RCApp.getM_videorecord().OnLowDiskSpace(localFile, str);
			VideoRecord.Record_Interrupted = true;
			this.RCApp.getM_videorecord().OnVideoRecordStop();
		}

		this.init_fps = this.RCApp.getVidClnt().getM_frameRate();

		VideoRecord.fps += this.init_fps;
	}

	public int getNum_blank_frames() {
		return this.num_blank_frames;
	}

	public void setNum_blank_frames(int paramInt) {
		this.num_blank_frames = paramInt;
	}
}

/*
 * Location: D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\
 * VideoRecordStart.class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */